package br.ufrj.neg.servlet;


import java.util.ArrayList;
import java.util.Date;
import java.util.PropertyResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import br.ufrj.neg.bean.Idioma;
import br.ufrj.neg.constants.ActionsConstants;
import br.ufrj.neg.constants.General;
import br.ufrj.neg.constants.VisualizationConstants;
import br.ufrj.neg.usuario.bean.UsuarioBean;
import br.ufrj.neg.util.PropertyLoader;

public class PageContext {
	public static General general = new General();
	public static VisualizationConstants visualizationsConstants = new VisualizationConstants();
	public static ActionsConstants actions = new ActionsConstants();
	
	private HttpServletRequest request;
	private HttpSession session;
	private Idioma idioma;
	private static PropertyResourceBundle enegProperties = PropertyLoader.getPropertyLoader().getPpt_eneg();
	
	private ArrayList<Object[]> contextBeansObjects;
	
	private String msgUsuario;
	
	public PageContext(HttpServletRequest request){
		this.contextBeansObjects = new ArrayList<Object[]>();
		this.request = request;
		this.session = request.getSession();
		this.idioma = (Idioma) request.getAttribute("idioma");
	}
		
	public String getProperty(String p){
		return enegProperties.getString(p);
	}

	public General getGeneral() {
		return general;
	}


	public HttpServletRequest getRequest() {
		return request;
	}

	public Idioma getIdioma() {
		return idioma;
	}	
	
	public boolean getPapel(int papel){
		if( getUserBean() != null ){
			return request.isUserInRole( String.valueOf(papel) );
		}
		else{
			return false;
		}
	}
	
	
	public UsuarioBean getUserBean(){
		return (UsuarioBean) session.getAttribute("usuarioBean"); 
	}
	
		
	public void addContextBeans(String name,Object bean){
		Object[] o = {name,bean};
		contextBeansObjects.add( o );
	}

	public String getMsgUsuario() {
		return msgUsuario;
	}
	
	public String getStrIdioma(){
		return this.idioma.getLocale().getLanguage();
	}

	public void setMsgUsuario(String msgUsuario) {
		this.msgUsuario = msgUsuario;
	}
	
	public String getJQuery(){
		return "$";
	}
	
	public String getAntiCache(){
		Date d = new Date();
		return String.valueOf( d.getSeconds() ) + String.valueOf( d.getMinutes() ) + String.valueOf( d.getHours() );
	}

	public static VisualizationConstants getVisualizationsConstants() {
		return visualizationsConstants;
	}

	public static ActionsConstants getActions() {
		return actions;
	}

	
}
